<template>
    <div class="main-con storeRealtimeInventory">
        <!-- 搜索框 -->
        <div class="search-con">
            <div class="search-item">
                <div class="search-item-title">门店编号</div>
                <div class="search-item-input">
                    <el-input size="mini" v-model="formData.storeNo" placeholder="请输入门店编号" @change="handleSearch"></el-input>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title">门店名称</div>
                <div class="search-item-input">
                    <el-input size="mini" v-model="formData.storeName" placeholder="请输入门店名称" @change="handleSearch"></el-input>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title">商品编号</div>
                <div class="search-item-input">
                    <el-input size="mini" v-model="formData.productNo" placeholder="请输入商品编号" @change="handleSearch"></el-input>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title">商品名称</div>
                <div class="search-item-input">
                    <el-input size="mini" v-model="formData.productName" placeholder="请输入商品名称" @change="handleSearch"></el-input>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title">大分类</div>
                <div class="search-item-input">
                    <el-select size="mini" v-model="formData.bigCategoryId" placeholder="请选择大分类" @change="_queryMidCategoryInfo(formData.bigCategoryId)">
                        <el-option v-for="item in bigCategoryOptions" :key="item.id" :label="item.categoryName" :value="item.id">
                        </el-option>
                    </el-select>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title">中分类</div>
                <div class="search-item-input">
                    <el-select size="mini" v-model="formData.midCategoryId" placeholder="请选择中分类" @change="_querySmaCategoryInfo(formData.midCategoryId)">
                        <el-option v-for="item in midCategoryOptions" :key="item.id" :label="item.categoryName" :value="item.id">
                        </el-option>
                    </el-select>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title">小分类</div>
                <div class="search-item-input">
                    <el-select size="mini" v-model="formData.smaCategoryId" placeholder="请选择小分类">
                        <el-option v-for="item in smaCategoryOptions" :key="item.id" :label="item.categoryName" :value="item.id">
                        </el-option>
                    </el-select>
                </div>
            </div>

            <div class="search-item">
                <div class="search-item-title">门店分组</div>
                <div class="search-item-input">
                    <el-select size="mini" v-model="formData.storeGroupId" placeholder="请选择门店分组">
                        <el-option v-for="item in storeGroupOptions" :key="item.value" :label="item.label" :value="item.value">
                        </el-option>
                    </el-select>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title"></div>
                <el-button size="mini" type="primary" icon="el-icon-search" @click="handleSearch">查询</el-button>
                <el-button size="mini" type="primary" icon="el-icon-delete" @click="handleClear">清空</el-button>
            </div>
        </div>

        <!-- 按钮组 -->
        <div class="btn-group-con">
            <el-button size="mini" type="primary" @click="handleExport">导出</el-button>
        </div>

        <!-- 表格数据 -->
        <div class="table-con" v-loading="loading">
            <el-table :data="tableData" size="mini" :header-cell-style="{background:'#f8f8f8'}" style="width: 100%">
                <el-table-column type="index" label="序号" width="50" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="storeName" label="门店名称" width="" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="productName" label="商品名称" width="" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="stockCount" label="总库存" width="" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="offLineSaleCount" label="门店销售" width="" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="onLineSaleCount" label="商城销售" width="" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="originPrice" label="原价" width="" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="specPrice" label="特价" width="" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <span v-if="scope.row.priceType != 0">{{scope.row.specPrice}}</span>
                        <span v-if="scope.row.priceType == 0">-</span>
                    </template>
                </el-table-column>
                <el-table-column prop="surplusCountOfOnLine" label="商城库存" width="" align="center"
                    :show-overflow-tooltip="true">
                </el-table-column>
            </el-table>
        </div>

        <!-- 表格分页 -->
        <div class="pagination-con">
            <m-pagination :currentPage="formData.pageNum" :pageSize="formData.pageSize" :total="total"
                @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange">
            </m-pagination>
        </div>
    </div>
</template>

<script>
import {
    queryBigCategoryInfo,
    queryOtherCategoryInfo
} from "@/common/service/productManagement/goodsInfo.js";
import { queryStoreRealtimeInventoryInfo } from "@/common/service/salesManagement/storeRealtimeInventory.js";
import mPagination from "@/components/m-pagination/m-pagination";
import { api } from "@/common/http/index.js";
export default {
    name: "storeRealtimeInventory",
    data() {
        return {
            // 搜索条件
            formData: {
                storeNo: "", //门店编号
                storeName: "", //门店名称
                productNo: "", //商品编号
                productName: "", //商品名称
                bigCategoryId: "", //大分类
                midCategoryId: "", //中分类
                smaCategoryId: "", //小分类
                storeGroupId: "", //门店分组
                pageNum: 1,
                pageSize: 10
            },
            //下拉框数据
            bigCategoryOptions: [], //大分类
            midCategoryOptions: [], //中分类
            smaCategoryOptions: [], //小分类
            storeGroupOptions: [], //门店分组
            //表格数据
            tableData: [], //表格信息
            total: null, //表格总条数
            loading: false //表格加载动画
        };
    },
    created() {
        //初始化大分类下拉框数据
        this._queryBigCategoryInfo();
        //初始化表格数据
        this._queryStoreRealtimeInventoryInfo();
    },
    methods: {
        /*----------------------------查询操作----------------------------*/
        //查询门店实时库存信息表格数据
        _queryStoreRealtimeInventoryInfo() {
            this.loading = true;
            queryStoreRealtimeInventoryInfo(this.formData)
                .then(res => {
                    this.loading = false;
                    this.tableData = res.list;
                    this.total = res.totalCount;
                })
                .catch(err => {
                    this.loading = false;
                    this.$message.error(err.message);
                });
        },
        //页码切换
        handleCurrentChange(val) {
            this.formData.pageNum = val;
            this._queryStoreRealtimeInventoryInfo();
        },
        //每页展示条数的切换
        handleSizeChange(val) {
            this.formData.pageSize = val;
            this._queryStoreRealtimeInventoryInfo();
        },
        //点击查询
        handleSearch() {
            this.formData.pageNum = 1;
            this.formData.pageSize = 10;
            this._queryStoreRealtimeInventoryInfo();
        },
        //点击清空
        handleClear() {
            this.formData = {
                storeNo: "",
                storeName: "",
                productNo: "",
                productName: "",
                bigCategoryId: "",
                midCategoryId: "",
                smaCategoryId: "",
                storeGroupId: "",
                pageNum: 1,
                pageSize: 10
            };
            this.$message({
                type: "success",
                message: "清空成功!"
            });
            this.getTodayTimeSection();
            this._queryStoreRealtimeInventoryInfo();
        },

        /*----------------------------分类查询操作----------------------------*/
        //查询大分类下拉框表格数据
        _queryBigCategoryInfo() {
            var data = {};
            queryBigCategoryInfo(data)
                .then(res => {
                    this.bigCategoryOptions = res;
                })
                .catch(err => {
                    this.$message.error(err.message);
                });
        },
        //查询中分类下拉框表格数据
        _queryMidCategoryInfo(opt) {
            var parentId = opt ? opt : this.formData.bigCategoryId;
            var data = {
                parentId: parentId
            };
            queryOtherCategoryInfo(data)
                .then(res => {
                    this.midCategoryOptions = res;
                    this.formData.midCategoryId = "";
                    this.formData.smaCategoryId = "";
                })
                .catch(err => {
                    this.$message.error(err.message);
                });
        },
        //查询小分类下拉框表格数据
        _querySmaCategoryInfo(opt) {
            var parentId = opt ? opt : this.formData.bigCategoryId;
            var data = {
                parentId: parentId
            };
            queryOtherCategoryInfo(data)
                .then(res => {
                    this.smaCategoryOptions = res;
                    this.formData.smaCategoryId = "";
                })
                .catch(err => {
                    this.$message.error(err.message);
                });
        },

        /*----------------------------导出操作----------------------------*/
        handleExport() {
            this.UTILS.exportUtil(
                api.exportStoreRealtimeInventoryInfo,
                this.formData
            );
        }
    },
    components: {
        "m-pagination": mPagination
    }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>